﻿using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using JQuery.WebKit.WebCommon;

namespace JQuery.WebKit
{
    [Designer("System.Web.UI.Design.HtmlIntrinsicControlDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
    public class JForm : HtmlForm, IWebControl
    {
        public JUpdater Updater
        {
            get;
            private set;
        }

        public string ProgressControlID
        {
            get
            {
                EnsureChildControls();
                return this.Updater != null ? this.Updater.ProgressControlID : string.Empty;
            }
            set
            {
                EnsureChildControls();
                if (this.Updater != null)
                {
                    this.Updater.ProgressControlID = value;
                }
            }
        }

        public string ErrorContainerID
        {
            get
            {
                EnsureChildControls();
                return this.Updater != null ? this.Updater.ErrorContainerID : string.Empty;
            }
            set
            {
                EnsureChildControls();
                if (this.Updater != null)
                {
                    this.Updater.ErrorContainerID = value;
                }
            }
        }

        public override ControlCollection Controls
        {
            get
            {
                if (DesignMode)
                {
                    return base.Controls;
                }
                EnsureChildControls();
                return Updater.Controls;
            }
        }

        public JForm() { }

        protected override void CreateChildControls()
        {
            if (!DesignMode && Updater == null)
            {
                Updater = new JUpdater();
                Updater.ID = "Updater";
                Updater.DeferLoad = false;
                base.Controls.Add(Updater);
            }

            base.CreateChildControls();
        }

        #region IWebControl Members

        public ControlCollection GetChildren()
        {
            return base.Controls;
        }

        #endregion
    }
}
